#pragma once
#include "egui.h"
#include "viewwnd.h"
#include "GoView.h"
class CMainMenuView : public CViewWnd
{
	DECLARE_DYNCREATE(CMainMenuView)

public:
	CMainMenuView(){	
		Init();
		m_pTestWidget=NULL;
	};           // protected constructor used by dynamic creation
	virtual ~CMainMenuView(){
		if(m_pDisplayManage!=NULL)
		{
			delete m_pDisplayManage;
			delete m_pRootContainer;
		}
		if(m_pGoView!=NULL)
		{
			delete m_pGoView;
		}
		if(this->m_pBarWidget!=NULL)
		{
			delete m_pBarWidget;
		}
		if(this->m_pListView!=NULL)
		{
			delete this->m_pListView;
		}
		if(this->m_pViewManager !=NULL)
		{
			delete this->m_pViewManager;
		}

	};

public:
	virtual void OnDraw(CDC* pDC);      // overridden to draw this view
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:
	DECLARE_MESSAGE_MAP()
public:



public:

	CContainerWidget* m_pRootContainer;
	CDisplayManage*  m_pDisplayManage;
	CViewManager*	m_pViewManager;
	CViewContainer* m_pListView;
	C3DListWidget* m_p3DListWidget;

	CListWidget* m_pListWidget;
	CWidget* m_pCurrentWidget;

	CGridMenuContainer* m_pMainMenu;

	CBarWidget* m_pBarWidget;
	CGoView* m_pGoView;

	CWidget* m_pTestWidget;


	ModelListener m_animateListener;
	virtual  void HandleAnimateListener(void *pUserData, ModelEvent *pEvent)
	{

	}
	void Init()
	{
		m_pDisplayManage=NULL;
		m_pRootContainer=NULL;
		m_pGoView=NULL;
		m_pListView=NULL;
		m_pBarWidget=NULL;
		InitListener();

	}
	virtual void InitListener()
	{
		GetEventListener()->pfnListener=HandleThreadSafeEvent;
		GetEventListener()->pListenerData = this;
		m_animateListener.pfnListener = StaticHandleAnimateListener;
		m_animateListener.pListenerData=this;
		m_animateListener.bEnableEventHandle=true;
	}

	static  void StaticHandleAnimateListener(void *pUserData, ModelEvent *pEvent)
	{
		CMainMenuView* me = (CMainMenuView*)pUserData;
		me->HandleAnimateListener(pUserData,pEvent);
	}

	static void HandleThreadSafeEvent(void *pUserData, ModelEvent *pEvent)
	{

		CMainMenuView* me = (CMainMenuView*)pUserData;
		ModelEvent* pClone = CloneEvent(pEvent);	 
		me->PostMessage(WM_EVENT_WRAPPER_FOR_THREAD_SAFE,(WPARAM)pClone,0);						
	}

	afx_msg LRESULT HandleModelEvent(WPARAM pModeEvent,LPARAM dummy);
	virtual void OnViewSwitchOut()
	{
		this->DisableEnventHandle();
		if(m_pDisplayManage!=NULL)
		{
			delete m_pDisplayManage;
			delete m_pRootContainer;
		}

		m_pDisplayManage=NULL;
	}


	virtual void RefreshUI();
	virtual void TestGridMenu();
	void TestListWidget();
	void TestGhostWidget();
	void TestBarWidget();
	void Test3DListWidget();
	afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);	
	afx_msg void OnSize(UINT nType, int cx, int cy);
	virtual void OnInitialUpdate()
	{
		this->RefreshUI();
	}
	void OnTest1();
	void OnTest2();
	void OnTest3();
	afx_msg void OnPaint();

	virtual BOOL PreTranslateMessage(MSG* pMsg);
};


